import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams, AlertController } from 'ionic-angular';
import { BusiProvider } from '../../providers/busi/busi';
import { NativeProvider } from '../../providers/native/native';

/**
 * Generated class for the TabsPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@IonicPage()
@Component({
  selector: 'page-tabs',
  templateUrl: 'tabs.html',
})
export class TabsPage {
  constructor(public navCtrl: NavController, public navParams: NavParams,private busi: BusiProvider, private native: NativeProvider, public alertCtrl: AlertController) {
  }

  ionViewDidLoad() {
    console.log('ionViewDidLoad TabsPage');
    setInterval(() => {
      this.getCloseToEndBooking();
    }, 10000);
  }

  getCloseToEndBooking() {
    this.busi.getCloseToEndBooking().subscribe(
      data => {
        if(data.classroom!=null){
          let classroomno = data.classroom.classroomno;
          let enddate = data.classroom.enddate;
          let bookedid = data.classroom.bookedid;
          let alert = this.alertCtrl.create({
            title: '教室到期提醒',
            message: "教室[" + classroomno + "]将于[" + enddate + "]到期，请注意!",
            buttons: [
              {
                text: "确定",
                handler: () => {
                  this.donotNotice(bookedid);
                }
              }
            ]
          });
          alert.present();
        }

      },
      error => {

      }
    )
  }

  donotNotice(bookid) {
    this.busi.closeNotice(bookid).subscribe(
      data=>{

      },
      error=>{

      }
    );
    }

}
